<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      :root {
        --flexDirection: row;
        --flexWrap: wrap;
        --item-basis: 100px;
        --gap: 1rem;
        --columns: 5;
      }
      .container {
        margin-top: 10px;
        width: calc(
          var(--item-basis) * var(--columns) + var(--gap) * (var(--columns) - 1) +
            6px
        );
      }
      .flex__container {
        display: flex;
        flex-flow: var(--flexDirection) var(--flexWrap);
      }
      .flex__container--margin {
        margin: calc(-1 * var(--gap)) 0 0 calc(-1 * var(--gap));
      }
      .flex__container--margin > .flex__item {
        margin: var(--gap) 0 0 var(--gap);
      }
      .flex__container--gap {
        gap: var(--gap);
      }
      .flex__item {
        inline-size: var(--item-basis);
        aspect-ratio: 1;
        background: #390;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="flex__container flex__container--margin" data-gutter="margin">
        <div class="flex__item">Flex Item 1</div>
        <div class="flex__item">Flex Item 2</div>
        <div class="flex__item">Flex Item 3</div>
        <div class="flex__item">Flex Item 4</div>
        <div class="flex__item">Flex Item 5</div>
        <div class="flex__item">Flex Item 1</div>
        <div class="flex__item">Flex Item 2</div>
        <div class="flex__item">Flex Item 3</div>
        <div class="flex__item">Flex Item 4</div>
        <div class="flex__item">Flex Item 5</div>
      </div>
    </div>
    <div class="container">
      <div class="flex__container flex__container--gap" data-gutter="gap">
        <div class="flex__item">Flex Item 1</div>
        <div class="flex__item">Flex Item 2</div>
        <div class="flex__item">Flex Item 3</div>
        <div class="flex__item">Flex Item 4</div>
        <div class="flex__item">Flex Item 5</div>
        <div class="flex__item">Flex Item 1</div>
        <div class="flex__item">Flex Item 2</div>
        <div class="flex__item">Flex Item 3</div>
        <div class="flex__item">Flex Item 4</div>
        <div class="flex__item">Flex Item 5</div>
      </div>
    </div>
  </body>
</html>
